#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 20001

int n;
struct Cow {
	int v, x;
	bool operator < (Cow a){
		return this->v < a.v;
	}
}cow[maxn], temp[maxn];
long long ans = 0;

//左闭右闭
void BinaryMerge(int l, int r){
	if(l >= r) return;
	int mid = (l+r)/2;
	BinaryMerge(l, mid);
	BinaryMerge(mid+1, r);
	
	//统计坐标差的和
	long long sLess = 0, sGreater = 0;
	for(int i=l; i<=mid; i++)
		sGreater += cow[i].x;
	int c = l;
	for(int i=mid+1; i<=r; i++){
		while(c<=mid && cow[c].x < cow[i].x){
			sLess += cow[c].x;
			sGreater -= cow[c].x;
			c++;
		}
		ans += ((c-l)*cow[i].x - sLess + sGreater - (mid-c+1)*cow[i].x)*cow[i].v;
	}
	//按x归并排序
	int i=l, j=mid+1, k=l;
	while(i<=mid && j<=r){
		if(cow[i].x <= cow[j].x)
			temp[k++]=cow[i++];
		else
			temp[k++]=cow[j++];
	}
	while(i<=mid)
		temp[k++]=cow[i++];
	while(j<=r)
		temp[k++]=cow[j++];
	for(i=l; i<=r; i++)
		cow[i]=temp[i];
}

int main(){
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>cow[i].v>>cow[i].x;
	}
	
	sort(cow, cow+n);
	BinaryMerge(0, n-1);
	
	cout<<ans<<endl;
	return 0;
}